import { setOauthHeaders } from '@/constants/header';
import HttpConfig from '@/constants/http.config';
import { ContainerEntity } from '@/models/container_entity';
import { TaroFetch } from '@/utils/fetch';
import {BranchApplyListModules} from 'types/branch'
const _fetch=new TaroFetch()
class BranchService {
    async getApplyList(params: {
        pageIndex: number;
        pageSize: number;
        audit_status: number;
    }) {
        let options = setOauthHeaders()
        return _fetch.request({
            url: `${HttpConfig.api}/branch/apply/list`,
            data: params,
            header:options.headers
        }).then((result) => {
            return result.data as  BranchApplyListModules.res_list
        }) 
    }
    /** 申请分支同意 */
    async checkout(id: string) {
        let options = setOauthHeaders()
        return _fetch.request({
            url: `${HttpConfig.api}/branch/apply/checkout`,
            data: {
                id,
            },
            header:options.headers,
        }).then((result) => {
            return result.data
        })
    }
    /** 删除分支申请请求数据 */
    async delete(id: string) {
        let options = setOauthHeaders()
        return _fetch.request({
            url: `${HttpConfig.api}/branch/apply/delete`,
            data: {
                id,
            },
            header: options.headers,
            method:'POST',
        }).then((result) => {
            return new ContainerEntity<boolean>(result.data)
        })
    }
    /** 驳回分支申请请求 */
    async reject(id: string) {
        let options = setOauthHeaders()
        return _fetch.request({
            url: `${HttpConfig.api}/branch/apply/reject`,
            data: {
                id,
            },
            header: options.headers,
            method:'POST',
        }).then((result) => {
            return new ContainerEntity<boolean>(result.data)
        }) 
    }
}

export const branchService = new BranchService()